﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmReportNguon.
	/// </summary>
	public class frmReportNguon : System.Windows.Forms.Form
	{
		//Khai bao gia tri mau cho form
		private int i_Red=255,i_Green=255,i_Blue=195;
		private bool kt_chon_ct=false;
		private int i_Iduser=0;
		private bool kt_chon_kp=false;
		private exportExcel exportExcel=new exportExcel();
		private DataTable dt_Dmnhombc,dt_Dmchuong,dt_Dmhoatdong,dt_Dmlk;
		private AccessData a;
		#region Control
		//Khai bao bien su dung trong form.
		private string s_Tenform="";
		private int i_HLoaikhoan=0;
		
		private Print Print=new Print();
		private System.Data.DataRow r;
		private System.Data.DataTable dtDmtk,dmMuc;
		private System.Data.DataSet ds_Data;
		private string sql="",s_Report="";

		#region Cac control su dung trong form.
		private System.Windows.Forms.Button butXem;
		private System.Windows.Forms.Button butIn;
		private System.Windows.Forms.Button butKetthuc;
		private LibList.List listLoaikhoan;
		private LibList.List listTaikhoan;
		private txtListBox.txtListBox txtSotaikhoan;
		protected txtListBox.txtListBox txtTentaikhoan;
		protected txtListBox.txtListBox txtTenloaikhoan;
		private System.Windows.Forms.NumericUpDown numDenthang;
		private System.Windows.Forms.NumericUpDown numTuthang;
		private System.Windows.Forms.NumericUpDown numNam;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.GroupBox grbThang;
		private System.Windows.Forms.RadioButton rdbTheongay;
		private System.Windows.Forms.RadioButton rdbTheothang;
		private System.Windows.Forms.GroupBox grbNgay;
		private System.Windows.Forms.DateTimePicker dtpDenngay;
		private System.Windows.Forms.DateTimePicker dtpTungay;
		private System.Windows.Forms.Label lblLoaikhoan;
		private System.Windows.Forms.Label lblTaikhoan;
		#endregion

		private System.Windows.Forms.GroupBox grpNen;
		private System.Windows.Forms.Label lblError;
		private System.Windows.Forms.GroupBox grbCheck;
		private LibList.List listMuc;
		protected txtListBox.txtListBox txtmuc;
		private txtListBox.txtListBox txtListMuc;
		private System.Windows.Forms.Label lblMuc;
		private System.Windows.Forms.ComboBox cboNguonKP;
		private System.Windows.Forms.TextBox txtnhombc;
		private System.Windows.Forms.TextBox txttennhombc;
		private System.Windows.Forms.Label label4;
		private LibList.List listnhombc;
		private System.Windows.Forms.TextBox txttenchuong;
		private System.Windows.Forms.TextBox txtchuong;
		private System.Windows.Forms.Label label5;
		private LibList.List listchuong;
		private System.Windows.Forms.TextBox txthoatdong;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox txttenhoatdong;
		private txtListBox.txtListBox txtLoaikhoan;
		private LibList.List listhoatdong;
		private System.Windows.Forms.Button butExcel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		#endregion

		public frmReportNguon(string s_Form,AccessData acc,int i_iduser)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			a=acc;
			i_Iduser=i_iduser;
			s_Tenform=s_Form;			
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
			try
			{
				a.Dispose();
				dtDmtk.Dispose();
				dt_Dmlk.Dispose();
				dmMuc.Dispose();
				ds_Data.Dispose();
			}
			catch{};
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmReportNguon));
			this.butXem = new System.Windows.Forms.Button();
			this.butIn = new System.Windows.Forms.Button();
			this.butKetthuc = new System.Windows.Forms.Button();
			this.listLoaikhoan = new LibList.List();
			this.listTaikhoan = new LibList.List();
			this.lblLoaikhoan = new System.Windows.Forms.Label();
			this.lblTaikhoan = new System.Windows.Forms.Label();
			this.txtSotaikhoan = new txtListBox.txtListBox();
			this.txtLoaikhoan = new txtListBox.txtListBox();
			this.txtTentaikhoan = new txtListBox.txtListBox();
			this.txtTenloaikhoan = new txtListBox.txtListBox();
			this.grbThang = new System.Windows.Forms.GroupBox();
			this.numDenthang = new System.Windows.Forms.NumericUpDown();
			this.numTuthang = new System.Windows.Forms.NumericUpDown();
			this.numNam = new System.Windows.Forms.NumericUpDown();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.grbNgay = new System.Windows.Forms.GroupBox();
			this.dtpDenngay = new System.Windows.Forms.DateTimePicker();
			this.label3 = new System.Windows.Forms.Label();
			this.dtpTungay = new System.Windows.Forms.DateTimePicker();
			this.label6 = new System.Windows.Forms.Label();
			this.grbCheck = new System.Windows.Forms.GroupBox();
			this.rdbTheothang = new System.Windows.Forms.RadioButton();
			this.rdbTheongay = new System.Windows.Forms.RadioButton();
			this.grpNen = new System.Windows.Forms.GroupBox();
			this.txthoatdong = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.txttenhoatdong = new System.Windows.Forms.TextBox();
			this.txttenchuong = new System.Windows.Forms.TextBox();
			this.txtchuong = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.txtnhombc = new System.Windows.Forms.TextBox();
			this.txttennhombc = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.lblMuc = new System.Windows.Forms.Label();
			this.txtListMuc = new txtListBox.txtListBox();
			this.txtmuc = new txtListBox.txtListBox();
			this.cboNguonKP = new System.Windows.Forms.ComboBox();
			this.listMuc = new LibList.List();
			this.lblError = new System.Windows.Forms.Label();
			this.listnhombc = new LibList.List();
			this.listchuong = new LibList.List();
			this.listhoatdong = new LibList.List();
			this.butExcel = new System.Windows.Forms.Button();
			this.grbThang.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.numDenthang)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.numTuthang)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.numNam)).BeginInit();
			this.grbNgay.SuspendLayout();
			this.grbCheck.SuspendLayout();
			this.grpNen.SuspendLayout();
			this.SuspendLayout();
			// 
			// butXem
			// 
			this.butXem.BackColor = System.Drawing.SystemColors.Control;
			this.butXem.ForeColor = System.Drawing.SystemColors.WindowText;
			this.butXem.Image = ((System.Drawing.Bitmap)(resources.GetObject("butXem.Image")));
			this.butXem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butXem.Location = new System.Drawing.Point(116, 264);
			this.butXem.Name = "butXem";
			this.butXem.Size = new System.Drawing.Size(60, 25);
			this.butXem.TabIndex = 41;
			this.butXem.Text = "     &Xem";
			this.butXem.Click += new System.EventHandler(this.butXem_Click);
			this.butXem.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// butIn
			// 
			this.butIn.BackColor = System.Drawing.SystemColors.Control;
			this.butIn.ForeColor = System.Drawing.SystemColors.WindowText;
			this.butIn.Image = ((System.Drawing.Bitmap)(resources.GetObject("butIn.Image")));
			this.butIn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butIn.Location = new System.Drawing.Point(240, 264);
			this.butIn.Name = "butIn";
			this.butIn.Size = new System.Drawing.Size(60, 25);
			this.butIn.TabIndex = 42;
			this.butIn.Text = "     &In";
			this.butIn.Click += new System.EventHandler(this.butIn_Click);
			this.butIn.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// butKetthuc
			// 
			this.butKetthuc.BackColor = System.Drawing.SystemColors.Control;
			this.butKetthuc.ForeColor = System.Drawing.SystemColors.WindowText;
			this.butKetthuc.Image = ((System.Drawing.Bitmap)(resources.GetObject("butKetthuc.Image")));
			this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butKetthuc.Location = new System.Drawing.Point(302, 264);
			this.butKetthuc.Name = "butKetthuc";
			this.butKetthuc.Size = new System.Drawing.Size(68, 25);
			this.butKetthuc.TabIndex = 43;
			this.butKetthuc.Text = "&Kết thúc";
			this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
			this.butKetthuc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// listLoaikhoan
			// 
			this.listLoaikhoan.BackColor = System.Drawing.SystemColors.Info;
			this.listLoaikhoan.ColumnCount = 0;
			this.listLoaikhoan.Location = new System.Drawing.Point(376, 296);
			this.listLoaikhoan.MatchBufferTimeOut = 1000;
			this.listLoaikhoan.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listLoaikhoan.Name = "listLoaikhoan";
			this.listLoaikhoan.Size = new System.Drawing.Size(75, 17);
			this.listLoaikhoan.TabIndex = 102;
			this.listLoaikhoan.TextIndex = -1;
			this.listLoaikhoan.TextMember = null;
			this.listLoaikhoan.ValueIndex = -1;
			this.listLoaikhoan.Visible = false;
			// 
			// listTaikhoan
			// 
			this.listTaikhoan.BackColor = System.Drawing.SystemColors.Info;
			this.listTaikhoan.ColumnCount = 0;
			this.listTaikhoan.Location = new System.Drawing.Point(88, 280);
			this.listTaikhoan.MatchBufferTimeOut = 1000;
			this.listTaikhoan.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listTaikhoan.Name = "listTaikhoan";
			this.listTaikhoan.Size = new System.Drawing.Size(75, 17);
			this.listTaikhoan.TabIndex = 101;
			this.listTaikhoan.TextIndex = -1;
			this.listTaikhoan.TextMember = null;
			this.listTaikhoan.ValueIndex = -1;
			this.listTaikhoan.Visible = false;
			// 
			// lblLoaikhoan
			// 
			this.lblLoaikhoan.BackColor = System.Drawing.SystemColors.Control;
			this.lblLoaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.lblLoaikhoan.Location = new System.Drawing.Point(32, 184);
			this.lblLoaikhoan.Name = "lblLoaikhoan";
			this.lblLoaikhoan.Size = new System.Drawing.Size(72, 23);
			this.lblLoaikhoan.TabIndex = 33;
			this.lblLoaikhoan.Text = "Loại khoản :";
			this.lblLoaikhoan.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// lblTaikhoan
			// 
			this.lblTaikhoan.BackColor = System.Drawing.SystemColors.Control;
			this.lblTaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.lblTaikhoan.Location = new System.Drawing.Point(16, 88);
			this.lblTaikhoan.Name = "lblTaikhoan";
			this.lblTaikhoan.Size = new System.Drawing.Size(88, 23);
			this.lblTaikhoan.TabIndex = 30;
			this.lblTaikhoan.Text = "Tài khoản :";
			this.lblTaikhoan.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtSotaikhoan
			// 
			this.txtSotaikhoan.BackColor = System.Drawing.SystemColors.Window;
			this.txtSotaikhoan.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtSotaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtSotaikhoan.Location = new System.Drawing.Point(96, 17);
			this.txtSotaikhoan.Name = "txtSotaikhoan";
			this.txtSotaikhoan.Size = new System.Drawing.Size(64, 21);
			this.txtSotaikhoan.TabIndex = 31;
			this.txtSotaikhoan.Text = "";
			this.txtSotaikhoan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSotaikhoan_KeyDown);
			this.txtSotaikhoan.DoubleClick += new System.EventHandler(this.txtSotaikhoan_DoubleClick);
			this.txtSotaikhoan.Validated += new System.EventHandler(this.txtSotaikhoan_Validated);
			this.txtSotaikhoan.TextChanged += new System.EventHandler(this.txtSotaikhoan_TextChanged);
			// 
			// txtLoaikhoan
			// 
			this.txtLoaikhoan.BackColor = System.Drawing.SystemColors.Window;
			this.txtLoaikhoan.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtLoaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtLoaikhoan.Location = new System.Drawing.Point(104, 184);
			this.txtLoaikhoan.Name = "txtLoaikhoan";
			this.txtLoaikhoan.Size = new System.Drawing.Size(63, 21);
			this.txtLoaikhoan.TabIndex = 33;
			this.txtLoaikhoan.Text = "";
			this.txtLoaikhoan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtLoaikhoan_KeyDown);
			this.txtLoaikhoan.DoubleClick += new System.EventHandler(this.txtLoaikhoan_DoubleClick);
			this.txtLoaikhoan.Validated += new System.EventHandler(this.txtLoaikhoan_Validated);
			this.txtLoaikhoan.TextChanged += new System.EventHandler(this.txtLoaikhoan_TextChanged);
			// 
			// txtTentaikhoan
			// 
			this.txtTentaikhoan.BackColor = System.Drawing.SystemColors.Window;
			this.txtTentaikhoan.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtTentaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtTentaikhoan.Location = new System.Drawing.Point(168, 88);
			this.txtTentaikhoan.Name = "txtTentaikhoan";
			this.txtTentaikhoan.ReadOnly = true;
			this.txtTentaikhoan.Size = new System.Drawing.Size(296, 21);
			this.txtTentaikhoan.TabIndex = 32;
			this.txtTentaikhoan.TabStop = false;
			this.txtTentaikhoan.Text = "";
			this.txtTentaikhoan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// txtTenloaikhoan
			// 
			this.txtTenloaikhoan.BackColor = System.Drawing.SystemColors.Window;
			this.txtTenloaikhoan.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtTenloaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtTenloaikhoan.Location = new System.Drawing.Point(168, 184);
			this.txtTenloaikhoan.Name = "txtTenloaikhoan";
			this.txtTenloaikhoan.ReadOnly = true;
			this.txtTenloaikhoan.Size = new System.Drawing.Size(298, 21);
			this.txtTenloaikhoan.TabIndex = 34;
			this.txtTenloaikhoan.TabStop = false;
			this.txtTenloaikhoan.Text = "";
			this.txtTenloaikhoan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// grbThang
			// 
			this.grbThang.Controls.AddRange(new System.Windows.Forms.Control[] {
																				   this.numDenthang,
																				   this.numTuthang,
																				   this.numNam,
																				   this.label1,
																				   this.label2,
																				   this.label8});
			this.grbThang.Enabled = false;
			this.grbThang.Location = new System.Drawing.Point(105, 40);
			this.grbThang.Name = "grbThang";
			this.grbThang.Size = new System.Drawing.Size(374, 36);
			this.grbThang.TabIndex = 3;
			this.grbThang.TabStop = false;
			// 
			// numDenthang
			// 
			this.numDenthang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.numDenthang.ForeColor = System.Drawing.Color.DarkBlue;
			this.numDenthang.Location = new System.Drawing.Point(148, 9);
			this.numDenthang.Maximum = new System.Decimal(new int[] {
																		12,
																		0,
																		0,
																		0});
			this.numDenthang.Minimum = new System.Decimal(new int[] {
																		1,
																		0,
																		0,
																		0});
			this.numDenthang.Name = "numDenthang";
			this.numDenthang.Size = new System.Drawing.Size(38, 21);
			this.numDenthang.TabIndex = 22;
			this.numDenthang.Value = new System.Decimal(new int[] {
																	  1,
																	  0,
																	  0,
																	  0});
			this.numDenthang.Enter += new System.EventHandler(this.numDenthang_Enter);
			this.numDenthang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.numDenthang.Leave += new System.EventHandler(this.numDenthang_Leave);
			// 
			// numTuthang
			// 
			this.numTuthang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.numTuthang.ForeColor = System.Drawing.Color.DarkBlue;
			this.numTuthang.Location = new System.Drawing.Point(64, 9);
			this.numTuthang.Maximum = new System.Decimal(new int[] {
																	   12,
																	   0,
																	   0,
																	   0});
			this.numTuthang.Minimum = new System.Decimal(new int[] {
																	   1,
																	   0,
																	   0,
																	   0});
			this.numTuthang.Name = "numTuthang";
			this.numTuthang.Size = new System.Drawing.Size(38, 21);
			this.numTuthang.TabIndex = 20;
			this.numTuthang.Value = new System.Decimal(new int[] {
																	 1,
																	 0,
																	 0,
																	 0});
			this.numTuthang.Enter += new System.EventHandler(this.numTuthang_Enter);
			this.numTuthang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.numTuthang.Leave += new System.EventHandler(this.numTuthang_Leave);
			// 
			// numNam
			// 
			this.numNam.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.numNam.ForeColor = System.Drawing.Color.DarkBlue;
			this.numNam.Location = new System.Drawing.Point(230, 9);
			this.numNam.Maximum = new System.Decimal(new int[] {
																   3004,
																   0,
																   0,
																   0});
			this.numNam.Minimum = new System.Decimal(new int[] {
																   2004,
																   0,
																   0,
																   0});
			this.numNam.Name = "numNam";
			this.numNam.Size = new System.Drawing.Size(48, 21);
			this.numNam.TabIndex = 24;
			this.numNam.Value = new System.Decimal(new int[] {
																 2004,
																 0,
																 0,
																 0});
			this.numNam.Enter += new System.EventHandler(this.numNam_Enter);
			this.numNam.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.numNam.Leave += new System.EventHandler(this.numNam_Leave);
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.SystemColors.Control;
			this.label1.ForeColor = System.Drawing.Color.DarkBlue;
			this.label1.Location = new System.Drawing.Point(189, 9);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(34, 23);
			this.label1.TabIndex = 23;
			this.label1.Text = "năm";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.SystemColors.Control;
			this.label2.ForeColor = System.Drawing.Color.DarkBlue;
			this.label2.Location = new System.Drawing.Point(108, 9);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(32, 23);
			this.label2.TabIndex = 21;
			this.label2.Text = "đến ";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label8
			// 
			this.label8.BackColor = System.Drawing.SystemColors.Control;
			this.label8.ForeColor = System.Drawing.Color.DarkBlue;
			this.label8.Location = new System.Drawing.Point(10, 9);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(49, 23);
			this.label8.TabIndex = 19;
			this.label8.Text = "Từ tháng";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// grbNgay
			// 
			this.grbNgay.Controls.AddRange(new System.Windows.Forms.Control[] {
																				  this.dtpDenngay,
																				  this.label3,
																				  this.dtpTungay,
																				  this.label6});
			this.grbNgay.Location = new System.Drawing.Point(105, 10);
			this.grbNgay.Name = "grbNgay";
			this.grbNgay.Size = new System.Drawing.Size(374, 36);
			this.grbNgay.TabIndex = 2;
			this.grbNgay.TabStop = false;
			// 
			// dtpDenngay
			// 
			this.dtpDenngay.CustomFormat = "dd/MM/yyyy";
			this.dtpDenngay.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dtpDenngay.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
			this.dtpDenngay.Location = new System.Drawing.Point(198, 9);
			this.dtpDenngay.Name = "dtpDenngay";
			this.dtpDenngay.Size = new System.Drawing.Size(80, 21);
			this.dtpDenngay.TabIndex = 18;
			this.dtpDenngay.Enter += new System.EventHandler(this.dtpDenngay_Enter);
			this.dtpDenngay.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.dtpDenngay.Leave += new System.EventHandler(this.dtpDenngay_Leave);
			// 
			// label3
			// 
			this.label3.BackColor = System.Drawing.SystemColors.Control;
			this.label3.ForeColor = System.Drawing.Color.DarkBlue;
			this.label3.Location = new System.Drawing.Point(145, 10);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(51, 23);
			this.label3.TabIndex = 17;
			this.label3.Text = "đến ngày";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// dtpTungay
			// 
			this.dtpTungay.CustomFormat = "dd/MM/yyyy";
			this.dtpTungay.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.dtpTungay.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
			this.dtpTungay.Location = new System.Drawing.Point(64, 9);
			this.dtpTungay.Name = "dtpTungay";
			this.dtpTungay.Size = new System.Drawing.Size(80, 21);
			this.dtpTungay.TabIndex = 16;
			this.dtpTungay.Enter += new System.EventHandler(this.dtpTungay_Enter);
			this.dtpTungay.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.dtpTungay.Leave += new System.EventHandler(this.dtpTungay_Leave);
			// 
			// label6
			// 
			this.label6.BackColor = System.Drawing.SystemColors.Control;
			this.label6.ForeColor = System.Drawing.Color.DarkBlue;
			this.label6.Location = new System.Drawing.Point(10, 10);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(49, 23);
			this.label6.TabIndex = 15;
			this.label6.Text = "Từ ngày";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// grbCheck
			// 
			this.grbCheck.Controls.AddRange(new System.Windows.Forms.Control[] {
																				   this.rdbTheothang,
																				   this.rdbTheongay});
			this.grbCheck.Location = new System.Drawing.Point(9, 10);
			this.grbCheck.Name = "grbCheck";
			this.grbCheck.Size = new System.Drawing.Size(98, 66);
			this.grbCheck.TabIndex = 1;
			this.grbCheck.TabStop = false;
			// 
			// rdbTheothang
			// 
			this.rdbTheothang.ForeColor = System.Drawing.Color.DarkBlue;
			this.rdbTheothang.Location = new System.Drawing.Point(11, 39);
			this.rdbTheothang.Name = "rdbTheothang";
			this.rdbTheothang.Size = new System.Drawing.Size(79, 24);
			this.rdbTheothang.TabIndex = 11;
			this.rdbTheothang.Text = "Theo tháng";
			this.rdbTheothang.CheckedChanged += new System.EventHandler(this.rdbTheothang_CheckedChanged);
			// 
			// rdbTheongay
			// 
			this.rdbTheongay.Checked = true;
			this.rdbTheongay.ForeColor = System.Drawing.Color.DarkBlue;
			this.rdbTheongay.Location = new System.Drawing.Point(11, 8);
			this.rdbTheongay.Name = "rdbTheongay";
			this.rdbTheongay.Size = new System.Drawing.Size(79, 24);
			this.rdbTheongay.TabIndex = 10;
			this.rdbTheongay.TabStop = true;
			this.rdbTheongay.Text = "Theo ngày";
			this.rdbTheongay.CheckedChanged += new System.EventHandler(this.rdbTheongay_CheckedChanged);
			// 
			// grpNen
			// 
			this.grpNen.BackColor = System.Drawing.SystemColors.Control;
			this.grpNen.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.txthoatdong,
																				 this.label7,
																				 this.txttenhoatdong,
																				 this.txttenchuong,
																				 this.txtchuong,
																				 this.label5,
																				 this.txtnhombc,
																				 this.txttennhombc,
																				 this.label4,
																				 this.lblMuc,
																				 this.txtListMuc,
																				 this.txtmuc,
																				 this.txtSotaikhoan,
																				 this.cboNguonKP});
			this.grpNen.Location = new System.Drawing.Point(9, 70);
			this.grpNen.Name = "grpNen";
			this.grpNen.Size = new System.Drawing.Size(471, 178);
			this.grpNen.TabIndex = 4;
			this.grpNen.TabStop = false;
			// 
			// txthoatdong
			// 
			this.txthoatdong.ForeColor = System.Drawing.Color.DarkBlue;
			this.txthoatdong.Location = new System.Drawing.Point(96, 88);
			this.txthoatdong.Name = "txthoatdong";
			this.txthoatdong.Size = new System.Drawing.Size(64, 20);
			this.txthoatdong.TabIndex = 155;
			this.txthoatdong.Text = "";
			this.txthoatdong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txthoatdong_KeyDown);
			this.txthoatdong.Validated += new System.EventHandler(this.txthoatdong_Validated);
			this.txthoatdong.TextChanged += new System.EventHandler(this.txthoatdong_TextChanged);
			this.txthoatdong.DoubleClick += new System.EventHandler(this.txthoatdong_DoubleClick);
			// 
			// label7
			// 
			this.label7.ForeColor = System.Drawing.Color.DarkBlue;
			this.label7.Location = new System.Drawing.Point(11, 88);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(85, 23);
			this.label7.TabIndex = 154;
			this.label7.Text = "Hoạt động:";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txttenhoatdong
			// 
			this.txttenhoatdong.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txttenhoatdong.ForeColor = System.Drawing.Color.DarkBlue;
			this.txttenhoatdong.Location = new System.Drawing.Point(160, 88);
			this.txttenhoatdong.Name = "txttenhoatdong";
			this.txttenhoatdong.Size = new System.Drawing.Size(296, 20);
			this.txttenhoatdong.TabIndex = 156;
			this.txttenhoatdong.Text = "";
			// 
			// txttenchuong
			// 
			this.txttenchuong.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txttenchuong.ForeColor = System.Drawing.Color.DarkBlue;
			this.txttenchuong.Location = new System.Drawing.Point(160, 64);
			this.txttenchuong.Name = "txttenchuong";
			this.txttenchuong.Size = new System.Drawing.Size(296, 20);
			this.txttenchuong.TabIndex = 153;
			this.txttenchuong.Text = "";
			// 
			// txtchuong
			// 
			this.txtchuong.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtchuong.Location = new System.Drawing.Point(96, 64);
			this.txtchuong.Name = "txtchuong";
			this.txtchuong.Size = new System.Drawing.Size(63, 20);
			this.txtchuong.TabIndex = 152;
			this.txtchuong.Text = "";
			this.txtchuong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtchuong_KeyDown);
			this.txtchuong.Validated += new System.EventHandler(this.txtchuong_Validated);
			this.txtchuong.TextChanged += new System.EventHandler(this.txtchuong_TextChanged);
			this.txtchuong.DoubleClick += new System.EventHandler(this.txtchuong_DoubleClick);
			// 
			// label5
			// 
			this.label5.ForeColor = System.Drawing.Color.DarkBlue;
			this.label5.Location = new System.Drawing.Point(11, 64);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(85, 23);
			this.label5.TabIndex = 151;
			this.label5.Text = "Chương:";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtnhombc
			// 
			this.txtnhombc.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtnhombc.Location = new System.Drawing.Point(96, 40);
			this.txtnhombc.Name = "txtnhombc";
			this.txtnhombc.Size = new System.Drawing.Size(64, 20);
			this.txtnhombc.TabIndex = 149;
			this.txtnhombc.Text = "";
			this.txtnhombc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtnhombc_KeyDown);
			this.txtnhombc.Validated += new System.EventHandler(this.txtnhombc_Validated);
			this.txtnhombc.TextChanged += new System.EventHandler(this.txtnhombc_TextChanged);
			this.txtnhombc.DoubleClick += new System.EventHandler(this.txtnhombc_DoubleClick);
			// 
			// txttennhombc
			// 
			this.txttennhombc.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.txttennhombc.ForeColor = System.Drawing.Color.DarkBlue;
			this.txttennhombc.Location = new System.Drawing.Point(160, 40);
			this.txttennhombc.Name = "txttennhombc";
			this.txttennhombc.Size = new System.Drawing.Size(296, 20);
			this.txttennhombc.TabIndex = 150;
			this.txttennhombc.Text = "";
			// 
			// label4
			// 
			this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label4.ForeColor = System.Drawing.Color.DarkBlue;
			this.label4.Location = new System.Drawing.Point(8, 40);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(88, 23);
			this.label4.TabIndex = 148;
			this.label4.Text = "Nhóm b/c:";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// lblMuc
			// 
			this.lblMuc.BackColor = System.Drawing.SystemColors.Control;
			this.lblMuc.ForeColor = System.Drawing.Color.DarkBlue;
			this.lblMuc.Location = new System.Drawing.Point(24, 144);
			this.lblMuc.Name = "lblMuc";
			this.lblMuc.Size = new System.Drawing.Size(64, 23);
			this.lblMuc.TabIndex = 125;
			this.lblMuc.Text = "Mục:";
			this.lblMuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtListMuc
			// 
			this.txtListMuc.BackColor = System.Drawing.SystemColors.Window;
			this.txtListMuc.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtListMuc.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtListMuc.Location = new System.Drawing.Point(96, 144);
			this.txtListMuc.Name = "txtListMuc";
			this.txtListMuc.Size = new System.Drawing.Size(64, 21);
			this.txtListMuc.TabIndex = 39;
			this.txtListMuc.Text = "";
			this.txtListMuc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtListMuc_KeyDown);
			this.txtListMuc.DoubleClick += new System.EventHandler(this.txtListMuc_DoubleClick);
			this.txtListMuc.Validated += new System.EventHandler(this.txtListMuc_Validated);
			this.txtListMuc.TextChanged += new System.EventHandler(this.txtListMuc_TextChanged);
			// 
			// txtmuc
			// 
			this.txtmuc.BackColor = System.Drawing.SystemColors.Window;
			this.txtmuc.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtmuc.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtmuc.Location = new System.Drawing.Point(160, 144);
			this.txtmuc.Name = "txtmuc";
			this.txtmuc.ReadOnly = true;
			this.txtmuc.Size = new System.Drawing.Size(296, 21);
			this.txtmuc.TabIndex = 40;
			this.txtmuc.TabStop = false;
			this.txtmuc.Text = "";
			this.txtmuc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// cboNguonKP
			// 
			this.cboNguonKP.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboNguonKP.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.cboNguonKP.ForeColor = System.Drawing.Color.DarkBlue;
			this.cboNguonKP.ImeMode = System.Windows.Forms.ImeMode.NoControl;
			this.cboNguonKP.Items.AddRange(new object[] {
															""});
			this.cboNguonKP.Location = new System.Drawing.Point(96, 17);
			this.cboNguonKP.Name = "cboNguonKP";
			this.cboNguonKP.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.cboNguonKP.Size = new System.Drawing.Size(360, 21);
			this.cboNguonKP.TabIndex = 131;
			// 
			// listMuc
			// 
			this.listMuc.BackColor = System.Drawing.SystemColors.Info;
			this.listMuc.ColumnCount = 0;
			this.listMuc.Location = new System.Drawing.Point(24, 264);
			this.listMuc.MatchBufferTimeOut = 1000;
			this.listMuc.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listMuc.Name = "listMuc";
			this.listMuc.Size = new System.Drawing.Size(80, 17);
			this.listMuc.TabIndex = 127;
			this.listMuc.TextIndex = -1;
			this.listMuc.TextMember = null;
			this.listMuc.ValueIndex = -1;
			this.listMuc.Visible = false;
			// 
			// lblError
			// 
			this.lblError.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblError.ForeColor = System.Drawing.Color.Maroon;
			this.lblError.Location = new System.Drawing.Point(9, 10);
			this.lblError.Name = "lblError";
			this.lblError.Size = new System.Drawing.Size(470, 120);
			this.lblError.TabIndex = 124;
			this.lblError.Text = "Báo cáo đang xây dựng !";
			this.lblError.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.lblError.Visible = false;
			// 
			// listnhombc
			// 
			this.listnhombc.BackColor = System.Drawing.SystemColors.Info;
			this.listnhombc.ColumnCount = 0;
			this.listnhombc.Location = new System.Drawing.Point(160, 304);
			this.listnhombc.MatchBufferTimeOut = 1000;
			this.listnhombc.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listnhombc.Name = "listnhombc";
			this.listnhombc.Size = new System.Drawing.Size(75, 17);
			this.listnhombc.TabIndex = 151;
			this.listnhombc.TextIndex = -1;
			this.listnhombc.TextMember = null;
			this.listnhombc.ValueIndex = -1;
			this.listnhombc.Visible = false;
			// 
			// listchuong
			// 
			this.listchuong.BackColor = System.Drawing.SystemColors.Info;
			this.listchuong.ColumnCount = 0;
			this.listchuong.Location = new System.Drawing.Point(264, 296);
			this.listchuong.MatchBufferTimeOut = 1000;
			this.listchuong.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listchuong.Name = "listchuong";
			this.listchuong.Size = new System.Drawing.Size(75, 17);
			this.listchuong.TabIndex = 154;
			this.listchuong.TextIndex = -1;
			this.listchuong.TextMember = null;
			this.listchuong.ValueIndex = -1;
			this.listchuong.Visible = false;
			// 
			// listhoatdong
			// 
			this.listhoatdong.BackColor = System.Drawing.SystemColors.Info;
			this.listhoatdong.ColumnCount = 0;
			this.listhoatdong.Location = new System.Drawing.Point(206, 160);
			this.listhoatdong.MatchBufferTimeOut = 1000;
			this.listhoatdong.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listhoatdong.Name = "listhoatdong";
			this.listhoatdong.Size = new System.Drawing.Size(75, 17);
			this.listhoatdong.TabIndex = 155;
			this.listhoatdong.TextIndex = -1;
			this.listhoatdong.TextMember = null;
			this.listhoatdong.ValueIndex = -1;
			this.listhoatdong.Visible = false;
			// 
			// butExcel
			// 
			this.butExcel.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.butExcel.BackColor = System.Drawing.SystemColors.Control;
			this.butExcel.ForeColor = System.Drawing.SystemColors.WindowText;
			this.butExcel.Image = ((System.Drawing.Bitmap)(resources.GetObject("butExcel.Image")));
			this.butExcel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butExcel.Location = new System.Drawing.Point(178, 264);
			this.butExcel.Name = "butExcel";
			this.butExcel.Size = new System.Drawing.Size(60, 25);
			this.butExcel.TabIndex = 156;
			this.butExcel.Text = "&Excel";
			this.butExcel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butExcel.Click += new System.EventHandler(this.butExcel_Click);
			// 
			// frmReportNguon
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(486, 315);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.butExcel,
																		  this.listhoatdong,
																		  this.listLoaikhoan,
																		  this.txtTenloaikhoan,
																		  this.grbNgay,
																		  this.grbThang,
																		  this.grbCheck,
																		  this.txtTentaikhoan,
																		  this.txtLoaikhoan,
																		  this.lblLoaikhoan,
																		  this.lblTaikhoan,
																		  this.butXem,
																		  this.butKetthuc,
																		  this.butIn,
																		  this.grpNen,
																		  this.lblError,
																		  this.listTaikhoan,
																		  this.listMuc,
																		  this.listnhombc,
																		  this.listchuong});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "frmReportNguon";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.TopMost = true;
			this.Click += new System.EventHandler(this.frmReportNguon_Click);
			this.Closing += new System.ComponentModel.CancelEventHandler(this.frmReportNguon_Closing);
			this.Load += new System.EventHandler(this.frmSocai_ct_theomuc_Load);
			this.grbThang.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.numDenthang)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numTuthang)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numNam)).EndInit();
			this.grbNgay.ResumeLayout(false);
			this.grbCheck.ResumeLayout(false);
			this.grpNen.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmSocai_ct_theomuc_Load(object sender, System.EventArgs e)
		{	
			//Tuy chon form Load
			f_VisibleCtl();
			f_Loadform();
			//End tuy chon.

			//Gan gia tri khoi tao cho cac o thang nam
			numTuthang.Value=DateTime.Now.Month;
			numDenthang.Value=DateTime.Now.Month;
			numNam.Value=DateTime.Now.Year;
			numNam.Value=DateTime.Now.Year;
			//

			listTaikhoan.DisplayMember="TTK";
			listTaikhoan.TextMember="STK";
			listTaikhoan.ValueMember="TTK";
			
			f_Loaddm();
			dtpTungay.Focus();
		}	

		#region load dm
		private void f_loadcomboNguon()
		{
			//do du lieu vao comboNguon
			ds_Data = a.get_DMNguon("");
			cboNguonKP.DataSource = ds_Data.Tables[0];
			cboNguonKP.DisplayMember = "TENNG";
			cboNguonKP.ValueMember = "ID";
		}
		private void f_LoadHoatdong()
		{
			listhoatdong.DisplayMember="TEN";
			listhoatdong.TextMember="MA";
			listhoatdong.ValueMember="TEN";
			dt_Dmhoatdong=a.get_DMHoatdong("").Tables[0];
			listhoatdong.DataSource=dt_Dmhoatdong;
		}
		private void f_LoadChuong()
		{
			listchuong.DisplayMember="TEN";
			listchuong.TextMember="MA";
			listchuong.ValueMember="TEN";

			dt_Dmchuong=a.get_DMChuong().Tables[0];
			listchuong.DataSource=dt_Dmchuong;
		}		
		private void f_LoadNhombc()
		{
			listnhombc.DisplayMember="TEN";
			listnhombc.ValueMember="TEN";
			listnhombc.TextMember="MA";

			dt_Dmnhombc=a.get_DMNhombc().Tables[0];
			listnhombc.DataSource=dt_Dmnhombc;						
		}
		private void f_LoadLoaikhoan()
		{
			listLoaikhoan.DisplayMember="TLK";
			listLoaikhoan.TextMember="LK";
			listLoaikhoan.ValueMember="TLK";

			dt_Dmlk=a.get_DMLoaikhoan().Tables[0];
			listLoaikhoan.DataSource=dt_Dmlk;
		}
		#endregion load dm
		private void f_VisibleCtl()
		{
			lblError.Visible=false;			
			cboNguonKP.Visible=false;	
		}

		private void f_Loadform()
		{					
			switch (s_Tenform)
			{				
				case "CTChiHoatDong":
					f_Loadform_CTChiHD("CTChiHoatDong");
					break;
				case "CTChiHoatDong_longan":
					f_Loadform_CTChiHD("CTChiHoatDong_longan");
					break;
				case "CTChiDuAn":
					f_Loadform_CTChiDuAn();
					break;
				case "TheoDoiNguonKP":
					f_Loadform_TheoDoiNguonKP();
					break;
				case "THNguonKP":
					f_Loadform_THNguonKP();
					break;				
				default:
					f_Loadform_Null();
					break;
			}
		}


		private void f_Loaddm()
		{
			f_LoadChuong();
			f_LoadHoatdong();
			f_LoadLoaikhoan();
			f_LoadNhombc();
			switch (s_Tenform)
			{				
				case "SOCAI_S3b":
					dtDmtk=a.get_DMTaikhoan("").Tables[0];
					break;
				case "CTChiHoatDong":
					dtDmtk=a.get_DMTaikhoan("661").Tables[0];	
					dmMuc=a.get_DMMuc().Tables[0];
					break;
				case "CTChiHoatDong_longan":
					dtDmtk=a.get_DMTaikhoan("661").Tables[0];	
					dmMuc=a.get_DMMuc().Tables[0];
					break;
				case "CTChiDuAn":
					dtDmtk=a.get_DMTaikhoan("662").Tables[0];
					dmMuc=a.get_DMMuc().Tables[0];
					break;
				case "TheoDoiNguonKP":
					dmMuc=a.get_DMMuc().Tables[0];
					f_loadcomboNguon();
					break;
				case "THNguonKP":
					dmMuc=a.get_DMMuc().Tables[0];
					f_loadcomboNguon();
					break;
				default:
					dtDmtk=a.get_DMTaikhoan("").Tables[0];
					break;
			}		
			listTaikhoan.TextMember="stk";
			listTaikhoan.DisplayMember="ttk";
			listTaikhoan.ValueMember="ttk";
			listTaikhoan.DataSource=dtDmtk;

			listMuc.TextMember="stk";
			listMuc.DisplayMember="ttk";
			listMuc.ValueMember="ttk";
			listMuc.DataSource=dmMuc;
		}

		private void hide_List()
		{
			if(!listTaikhoan.Focused) listTaikhoan.Hide();
			if(!listLoaikhoan.Focused) listLoaikhoan.Hide();
			if(!listMuc.Focused)listMuc.Hide();
			if(!listchuong.Focused)listchuong.Hide();
			if(!listhoatdong.Focused)listhoatdong.Hide();
			if(!listnhombc.Focused)listnhombc.Hide();
		}

		private void f_Loadform_Null()
		{
			this.Text="BÁO CÁO ĐANG XÂY DỰNG!";
			this.Height=248;
			grbCheck.Dispose(); grbNgay.Dispose(); grbThang.Dispose();
			grpNen.Dispose();
			lblTaikhoan.Dispose(); txtSotaikhoan.Dispose(); txtTentaikhoan.Dispose();
			lblLoaikhoan.Dispose(); txtLoaikhoan.Dispose(); txtTenloaikhoan.Dispose();			
			butXem.Dispose(); butIn.Dispose(); 
			lblError.Visible=true; lblError.BringToFront();
			butKetthuc.Left=206; butKetthuc.Top=160;
			
		}
		private void f_Loadform_CTChiHD(string s_tenform)
		{
			switch(s_tenform)
			{
				case "CTChiHoatDong":
					this.Text="SỔ CHI TIẾT CHI HOẠT ĐỘNG (MẪU SỐ S61-H)";
					this.Height=310;
					grpNen.Height=170;

					butXem.Top=245; butExcel.Top=245; butIn.Top=245; butKetthuc.Top=245;	            					
					s_Report="KT_rChiHoatDong.rpt";	
					break;
				case "CTChiHoatDong_longan":
					this.Text="SỔ CHI TIẾT CHI HOẠT ĐỘNG - ĐẶT THÙ CỦA BỆNH VIỆN";
					this.Height=310;
					grpNen.Height=170;

					butXem.Top=245; butExcel.Top=245; butIn.Top=245; butKetthuc.Top=245;	            					
					s_Report="KT_rChiHoatDong_la.rpt";	
					break;
			}

		}	
		private void f_Loadform_CTChiDuAn()
		{
			//kt_chon_da=true;
			this.Text="SỔ CHI TIẾT CHI DỰ ÁN (MẤU SỐ S62-H)";
			this.Height=310;
			grpNen.Height=170;			

			butXem.Top=245; butExcel.Top=245; butIn.Top=245; butKetthuc.Top=245;
										
			s_Report="KT_rSoChiDuAn.rpt";	
		}
		private void f_Loadform_TheoDoiNguonKP()
		{
			kt_chon_kp=true;
			this.Text="SỔ THEO DÕI NGUỒN KINH PHÍ (MẤU SỐ S42-H)";
			this.Height=310;
			grpNen.Height=170;

			//hien control nguon
			lblTaikhoan.Text="Nguồn:";
			cboNguonKP.Visible=true;
			//cboNguonKP.Top=88;
			
			txtSotaikhoan.Visible=false;
			txtTentaikhoan.Visible=false;
			listTaikhoan.Visible=false;
			
			
			butXem.Top=245; butExcel.Top=245; butIn.Top=245; butKetthuc.Top=245;
			            					
			s_Report="KT_rTheoDoiNguonKP.rpt";	
		}
		private void f_Loadform_THNguonKP()
		{
			kt_chon_kp=true;
			this.Text="SỔ TỔNG HỢP NGUỒN KINH PHÍ (MẤU SỐ S43-H)";
			this.Height=310;
			grpNen.Height=170;
			
			//hien control nguon
			lblTaikhoan.Text="Nguồn:";
			cboNguonKP.Visible=true;
			//cboNguonKP.Top=88;
			
			txtSotaikhoan.Visible=false;
			txtTentaikhoan.Visible=false;
			listTaikhoan.Visible=false;
			
			
			butXem.Top=245; butIn.Top=245; butKetthuc.Top=245;butExcel.Top=245;
			            					
			s_Report="KT_rTongHopNguonKP.rpt";	
		}
		private void event_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab || e.KeyValue==13)
			{
				SendKeys.Send("{Tab}");
			}
		}
		#region cac ham xu ly ngay thang
		private void numTuthang_Enter(object sender, System.EventArgs e)
		{
			this.numTuthang.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void numDenthang_Enter(object sender, System.EventArgs e)
		{
			this.numDenthang.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}
		
		private void numNam_Enter(object sender, System.EventArgs e)
		{
			this.numNam.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void dtpTungay_Enter(object sender, System.EventArgs e)
		{
			this.dtpTungay.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void dtpDenngay_Enter(object sender, System.EventArgs e)
		{
			this.dtpDenngay.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void numTuthang_Leave(object sender, System.EventArgs e)
		{
			this.numTuthang.BackColor = System.Drawing.SystemColors.Window;
		}

		private void numDenthang_Leave(object sender, System.EventArgs e)
		{
			this.numDenthang.BackColor = System.Drawing.SystemColors.Window;
		}

		private void numNam_Leave(object sender, System.EventArgs e)
		{
			this.numNam.BackColor = System.Drawing.SystemColors.Window;
		}

		private void dtpTungay_Leave(object sender, System.EventArgs e)
		{
			this.dtpTungay.BackColor = System.Drawing.SystemColors.Window;
		}

		private void dtpDenngay_Leave(object sender, System.EventArgs e)
		{
			this.dtpDenngay.BackColor = System.Drawing.SystemColors.Window;
		}
		#endregion ket thuc ham xu ly ngay thang
		private void Filter_List(LibList.List listDulieu,string s_Dkloc,string s_Tenfield_1,string s_Tenfield_2)
		{
			try
			{
				string s_Dieukien=s_Tenfield_1.Trim()+" like '%"+s_Dkloc.Trim()+"%'";
				if (s_Tenfield_2.Trim()!="") s_Dieukien+=" or "+s_Tenfield_2.Trim()+" like '%"+s_Dkloc.Trim()+"%'";
				CurrencyManager cm= (CurrencyManager)BindingContext[listDulieu.DataSource];
				System.Data.DataView dv=(System.Data.DataView)cm.List;
				dv.RowFilter=s_Dieukien;
			}
			catch{}
		}
		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}


		#region cac ham xu ly loc du lieu tuong ung do vao textbox
		private void txtSotaikhoan_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listTaikhoan.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listTaikhoan.Visible) listTaikhoan.Focus();
				else SendKeys.Send("{Tab}");
			}
		}

		private void txtSotaikhoan_DoubleClick(object sender, System.EventArgs e)
		{
			listTaikhoan.Focus();
			//Filter_List(txtSotaikhoan.Text,1);
			Filter_List(listTaikhoan,txtSotaikhoan.Text.Trim(),"stk","");
			listTaikhoan.BrowseToDmtk(txtSotaikhoan,txtTentaikhoan,txtnhombc,txtSotaikhoan.Location.X+8,104,txtSotaikhoan.Width+txtTentaikhoan.Width+2,txtSotaikhoan.Height,100);
		}

		private void txtSotaikhoan_TextChanged(object sender, System.EventArgs e)
		{
			
			if (this.ActiveControl==txtSotaikhoan)
			{
				//Filter_List(txtSotaikhoan.Text,1);				
				Filter_List(listTaikhoan,txtSotaikhoan.Text.Trim(),"stk","");
				listTaikhoan.BrowseToDmtk(txtSotaikhoan,txtTentaikhoan,txtnhombc,txtSotaikhoan.Location.X+8,104,txtSotaikhoan.Width+txtTentaikhoan.Width+2,txtSotaikhoan.Height,100);
			}	
		}

		private void txtSotaikhoan_Validated(object sender, System.EventArgs e)
		{
			txtTentaikhoan.Text="";
			if (txtSotaikhoan.Text!="")
			{
				r=a.getrowbyid(dtDmtk,"stk='"+txtSotaikhoan.Text.Trim()+"'");
				if (r!=null) 
				{
					txtTentaikhoan.Text=r["ttk"].ToString();
				}
			}
			hide_List();
		}

		private void txtLoaikhoan_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listLoaikhoan.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listLoaikhoan.Visible) listLoaikhoan.Focus();
				else SendKeys.Send("{Tab}");
			}
		}

		private void txtLoaikhoan_DoubleClick(object sender, System.EventArgs e)
		{
			listLoaikhoan.Focus();
			Filter_List(listLoaikhoan,txtLoaikhoan.Text.Trim(),"lk","");
			listLoaikhoan.BrowseToDmtk(txtLoaikhoan,txtTenloaikhoan,txtListMuc,txtLoaikhoan.Location.X,txtLoaikhoan.Location.Y + txtLoaikhoan.Height-2,txtLoaikhoan.Width+0+txtTenloaikhoan.Width,txtLoaikhoan.Height+i_HLoaikhoan,100);
		}

		private void txtLoaikhoan_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtLoaikhoan)
			{
				Filter_List(listLoaikhoan,txtLoaikhoan.Text.Trim(),"lk","");
				listLoaikhoan.BrowseToDmtk(txtLoaikhoan,txtTenloaikhoan,txtListMuc,txtLoaikhoan.Location.X,txtLoaikhoan.Location.Y + txtLoaikhoan.Height-2,txtLoaikhoan.Width+0+txtTenloaikhoan.Width,txtLoaikhoan.Height+i_HLoaikhoan,100);
			}	
		}

		private void txtLoaikhoan_Validated(object sender, System.EventArgs e)
		{
			txtTenloaikhoan.Text="";
			if (txtLoaikhoan.Text!="")
			{
				r=a.getrowbyid(dt_Dmlk,"lk='"+txtLoaikhoan.Text.Trim()+"'");
				if (r!=null) 
				{
					txtTenloaikhoan.Text=r["tlk"].ToString();
				}
			}
			hide_List();
		}
		private void txtListMuc_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtListMuc)
			{
				Filter_List(listMuc,txtmuc.Text.Trim(),"mtm","");;
				listMuc.BrowseToDmtk(txtListMuc,txtmuc,butXem,txtListMuc.Location.X+9,(txtListMuc.Location.X+txtListMuc.Location.Y)-8,txtListMuc.Width+0+txtmuc.Width,txtListMuc.Height,100);
			}	
		}

		private void txtListMuc_Validated(object sender, System.EventArgs e)
		{
			txtmuc.Text="";
			if (txtListMuc.Text!="")
			{
				r=a.getrowbyid(dmMuc,"stk='"+txtListMuc.Text.Trim()+"'");
				if (r!=null) 
				{
					txtmuc.Text=r["ttk"].ToString();
				}
			}
			hide_List();
		}

		private void txtListMuc_DoubleClick(object sender, System.EventArgs e)
		{
			listMuc.Focus();
			Filter_List(listMuc,txtmuc.Text.Trim(),"mtm","");
			listMuc.BrowseToDmtk(txtListMuc,txtmuc,butXem,txtListMuc.Location.X+9,(txtListMuc.Location.X+txtListMuc.Location.Y)-8,txtListMuc.Width+0+txtmuc.Width,txtListMuc.Height,100);
		}

		private void txtListMuc_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listMuc.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listMuc.Visible) listMuc.Focus();
				else SendKeys.Send("{Tab}");
			}
		}
		#endregion dong cac lenh xu ly loc du lieu.
		private bool Kiemtra()
		{
			if ((numDenthang.Value<numTuthang.Value)&&(rdbTheothang.Checked))
			{
				MessageBox.Show("Bạn đã chọn từ tháng lớn hơn đến tháng!","Chú ý!");
				numDenthang.Focus();
				return false;
			}
			if (rdbTheongay.Checked)
			{
				if (dtpTungay.Value.Year<dtpDenngay.Value.Year)
				{
					MessageBox.Show("Bạn chọn số liệu quá nhiều năm!","Chú ý!");
					dtpDenngay.Focus();
					return false;
				}
				if (dtpTungay.Value>dtpDenngay.Value) 
				{
					MessageBox.Show("Bạn đã chọn từ ngày lớn hơn đến ngày!","Chú ý!");
					dtpDenngay.Focus();
					return false;
				}						
			}
			if (txtSotaikhoan.Text==""&&kt_chon_kp==false)
			{
				MessageBox.Show("Vui lòng nhập số tài khoản!","Chú ý!");
				txtSotaikhoan.Focus();
				return false;
			}
			if(txthoatdong.Text==""&&kt_chon_ct==true)
			{
				MessageBox.Show("Vui lòng nhập loại hoạt động!","Chú ý!");
				txthoatdong.Focus();
				return false;
			}
			return true;
		}

		private void Display(int loai)
		//Loai display: 1 - xuat ra man hinh; 2 - xuat ra may in. 
		{
			if (Kiemtra()) //Kiem tra dieu kien nhap vao.
			{
				//Gan dieu kien vao cac bien.
				frmReportNguon_class accMyform=new frmReportNguon_class();
				ds_Data=new System.Data.DataSet();
				int yy=rdbTheongay.Checked?int.Parse(dtpTungay.Value.Year.ToString()):int.Parse(numNam.Value.ToString());
				int mm1=rdbTheongay.Checked?int.Parse(dtpTungay.Value.Month.ToString()):int.Parse(numTuthang.Value.ToString());
				int mm2=rdbTheongay.Checked?int.Parse(dtpDenngay.Value.Month.ToString()):int.Parse(numDenthang.Value.ToString());
				string s_mm=mm1.ToString().PadLeft(2,'0');
				string s_mm2=mm2.ToString().PadLeft(2,'0');
				string s_yyyy=rdbTheongay.Checked?(dtpTungay.Value.Year.ToString()):(numNam.Value.ToString());
				string s_yy=s_yyyy.Substring(2,2);
				string s_Tungay=rdbTheongay.Checked?dtpTungay.Value.ToString("dd/MM/yyyy"):numTuthang.Value.ToString().PadLeft(2,'0')+"/"+numNam.Value.ToString().PadLeft(4,'0');
				string s_Denngay=rdbTheongay.Checked?dtpDenngay.Value.ToString("dd/MM/yyyy"):numDenthang.Value.ToString().PadLeft(2,'0')+"/"+numNam.Value.ToString().PadLeft(4,'0');
				string s_IDtk="",s_IDlk="";
				string s_sotk="",s_ttk="";
				string idChuong="",idHoatdong="",s_IDmuc="",idNhombc="",s_muc="";

				string s_Thangnam=a.kt_Tinhsodu(s_mm2.ToString(),s_yy);
				if (s_Thangnam!="")
				{
					MessageBox.Show("Các tháng "+s_Thangnam.Substring(0,s_Thangnam.Length-1)+" chưa tính số dư!","Chú ý!");
					//xac minh co tinh so du
					if (MessageBox.Show ("Bạn có muốn kiểm tra số dư không ?",this.Text,MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
					{
						//tinh so du
						string sql="",_tu="",_den="";
						_den=s_mm2+s_yyyy.Substring(2,2);			
						//lay thang tu						
						sql="select mmyy from (select *  from a_dtsd where substr(trim(mmyy),3,4)='"+s_yy+"' order by mmyy asc) where rownum=1";
						DataSet ds=new DataSet();
						ds=a.get_data(sql);
						if(ds!=null && ds.Tables[0].Rows.Count>0)
							_tu=ds.Tables[0].Rows[0]["mmyy"].ToString();
						else _tu=s_mm+s_yyyy.Substring(2,2);			
						if (!a.bYyyy(s_yyyy))
						{
							MessageBox.Show("Số liệu năm "+s_yyyy+" chưa tạo !",a.Msg);
							return;
						}
						string s=a.KiemtraFb(_tu,_den);
						if (s!="")
						{
							MessageBox.Show("Số liệu tháng :"+s.Substring(0,s.Length-1)+" Năm "+s_yyyy+" bị khóa !");    		
							return;
						}
						else 
						{
							Cursor=Cursors.WaitCursor;                            
							a.KiemtraFb(_tu,_den,i_Iduser);
							Cursor=Cursors.Default;
						}
						//a.updSodu(_tu,a.Mmyy_sau(_den),i_Iduser,false);
						MessageBox.Show("Đã kiểm tra số dư cuối tháng "+_tu.Substring(0,2)+" đến tháng "+_den.Substring(0,2)+" năm 20"+s_yy+" !",a.Msg);					
						//
					}
					return;
				}

				try
				{
					if(kt_chon_kp==false)
					{
						int i_LengthTK=txtSotaikhoan.Text.ToString().Trim().Length;
						sql="select id from a_dmtk where substr(stk,1,"+i_LengthTK+")='"+txtSotaikhoan.Text.Trim()+"' order by id";
						foreach(System.Data.DataRow dr in a.get_data(sql).Tables[0].Rows)
						{ 
							s_IDtk+=dr["id"].ToString()+",";
						}
						if (s_IDtk.Substring(s_IDtk.Length-1,1)==",") s_IDtk=s_IDtk.Substring(0,s_IDtk.Length-1);
						if(txtSotaikhoan.Text!="") s_sotk=txtSotaikhoan.Text;
						if(txtTentaikhoan.Text!="") s_ttk=txtTentaikhoan.Text;
					}
					if (txtLoaikhoan.Text!="") s_IDlk=a.getrowbyid(dt_Dmlk,"lk='"+txtLoaikhoan.Text.Trim()+"'")["id"].ToString().Trim();
					if (txtchuong.Text.Trim()!="") idChuong=a.getrowbyid(dt_Dmchuong,"ma='"+txtchuong.Text.Trim()+"'")["id"].ToString().Trim();					
					if (txttennhombc.Text!="") idNhombc=a.getrowbyid(dt_Dmnhombc,"ma='"+txtnhombc.Text.Trim()+"'")["id"].ToString().Trim();
					if (txthoatdong.Text!="") idHoatdong=a.getrowbyid(dt_Dmhoatdong,"ma='"+txthoatdong.Text.Trim()+"'")["id"].ToString().Trim();
					if(txtListMuc.Text!="")
					{
						s_IDmuc=a.getrowbyid(dmMuc,"stk='"+txtListMuc.Text.Trim()+"'")["id"].ToString().Trim();					
						s_muc=txtListMuc.Text;
					}
				}
				catch{}	;
				
				//Load data cua tung mau bao cao.
				switch (s_Tenform)
				{	
					case "CTChiHoatDong":						
						ds_Data=accMyform.SoCTChiHoatDong(a, s_sotk,s_IDlk, s_Tungay, s_Denngay,mm1.ToString().PadLeft(2,'0'),mm2.ToString().PadLeft(2,'0'),s_yy,s_yyyy,rdbTheongay.Checked,idChuong,idHoatdong,s_muc, idNhombc);
						accMyform.Dispose();
						break;
					case "CTChiHoatDong_longan":						
						ds_Data=accMyform.SoCTChiHoatDong(a, s_sotk,s_IDlk, s_Tungay, s_Denngay,mm1.ToString().PadLeft(2,'0'),mm2.ToString().PadLeft(2,'0'),s_yy,s_yyyy,rdbTheongay.Checked,idChuong,idHoatdong,s_muc, idNhombc);
						accMyform.Dispose();
						break;
					case "CTChiDuAn":
						ds_Data=accMyform.SoCTChiDuAn(a,s_IDlk,s_sotk,s_ttk,s_muc, s_yy,rdbTheongay.Checked,mm1.ToString().PadLeft(2,'0') ,mm2.ToString().PadLeft(2,'0'),s_Tungay,s_Denngay,idChuong,idHoatdong, idNhombc);
						accMyform.Dispose();
						break;
					case "TheoDoiNguonKP":
						ds_Data=accMyform.soTheoDoiNguonKP(a,s_IDlk,s_muc,s_yy,rdbTheongay.Checked,mm1.ToString().PadLeft(2,'0'),mm2.ToString().PadLeft(2,'0'),s_Tungay,s_Denngay,idChuong,idHoatdong,idNhombc,cboNguonKP.SelectedValue.ToString());
						accMyform.Dispose();
						break;
					case "THNguonKP":
						ds_Data=accMyform.soTongHopNguonKP(a,s_sotk,s_IDlk,s_Tungay,s_Denngay,mm1.ToString().PadLeft(2,'0'),mm2.ToString().PadLeft(2,'0'),s_yy,s_yyyy,rdbTheongay.Checked,idChuong,idHoatdong,s_muc,idNhombc,cboNguonKP.SelectedValue.ToString());
						accMyform.Dispose();
						break;					
					default: 
						break;
				}

				try
				{
					if (ds_Data==null) MessageBox.Show("Không có số liệu !","Thông báo !");
					else
					{
						string title_Ngaythang="",title_Taikhoan="",title_Sotk="";
						string title_Loai="",title_Khoan="";
						string chuky1="",chuky2="",chuky3="",chuky4="",sMaso="";
						string sNam= yy.ToString(),sTenDA="",sChuongTrinh="",sNamKD="",sNamKT="";
						string sMuc="",sTenTKC2="";
						string sLoaiKP="",sNguonKP;
						string title_Doituong="";
						string mang="";
						//lay ten tai khoan cap 2
						int length=txtSotaikhoan.Text.Trim().Length;
						if(length>5)
						{
							string sTKC2=txtSotaikhoan.Text.Trim().Split('.')[0].ToString();
							mang=txtSotaikhoan.Text.Trim().Split('.')[1].ToString();
							string sql_c2="";
							sql_c2="select ttk from a_dmtk where stk like '"+sTKC2+"'";
							System.Data.DataSet ds_c2;
							ds_c2=a.get_data(sql_c2);
							sTenTKC2=ds_c2.Tables[0].Rows[0][0].ToString();
												
							//lay cac thong so cua table a_dmng
							if(txthoatdong.Text!="")
							{
								string sql="";							
								System.Data.DataSet ds_ng;
								sql+=" select mang, ten,thuocct,ngaybd,ngaykt,mada from a_dmng";
								sql+=" where mang="+mang;
								sql+=" and loaikp=0";
								ds_ng = a.get_data(sql);								
								//if ((ds_Data==null || ds_Data.Tables[0].Rows.Count<=0))
								if (ds_ng!=null && ds_ng.Tables[0].Rows.Count>0)
								{
									sTenDA=ds_ng.Tables[0].Rows[0]["ten"].ToString();
									sMaso=ds_ng.Tables[0].Rows[0]["mada"].ToString();
									sChuongTrinh=ds_ng.Tables[0].Rows[0]["thuocct"].ToString();
									sNamKD=ds_ng.Tables[0].Rows[0]["ngaybd"].ToString();						
									sNamKT=ds_ng.Tables[0].Rows[0]["ngaykt"].ToString();
									//sTenDA="DTPT";
								}
							}					
						}
						//	
						if (rdbTheongay.Checked)
						{
							if (s_Tungay==s_Denngay) title_Ngaythang="Ngày "+s_Tungay;
							else title_Ngaythang="Từ ngày "+s_Tungay+" đến ngày "+s_Denngay;
						}
						else
						{
							if (mm1==mm2) title_Ngaythang="Tháng "+mm1+" năm "+yy;
							else title_Ngaythang="Từ tháng "+mm1+" đến tháng "+mm2+" năm "+yy;
						}
						title_Taikhoan="Tài khoản : "+txtSotaikhoan.Text+" - "+txtTentaikhoan.Text;
						title_Sotk=txtSotaikhoan.Text;
						sLoaiKP=txttenhoatdong.Text;
						sNguonKP=cboNguonKP.Text;
						switch (s_Tenform)
						{
							case "CTChiDuAn": 
								if (txtLoaikhoan.Text!="") 
								{
									title_Loai=txtLoaikhoan.Text.Trim().Split('-')[0].ToString();
									title_Khoan=txtLoaikhoan.Text.Trim().Split('-')[1].ToString();
								}
								if(txtListMuc.Text!="")
									sMuc=txtListMuc.Text;
								break;
							case "CTChiHoatDong": 
								if (txtLoaikhoan.Text!="") 
								{
									title_Loai=txtLoaikhoan.Text.Trim().Split('-')[0].ToString();
									title_Khoan=txtLoaikhoan.Text.Trim().Split('-')[1].ToString();
								}
								break;
							case "CTChiHoatDong_longan": 
								if (txtLoaikhoan.Text!="") 
								{
									title_Loai=txtLoaikhoan.Text.Trim().Split('-')[0].ToString();
									title_Khoan=txtLoaikhoan.Text.Trim().Split('-')[1].ToString();
								}
								break;
							case "TheoDoiNguonKP":
								if (txtLoaikhoan.Text!="") 
								{
									title_Loai=txtLoaikhoan.Text.Trim().Split('-')[0].ToString();
									title_Khoan=txtLoaikhoan.Text.Trim().Split('-')[1].ToString();
								}
								break;

							default: 
								break;
						}
						switch(loai)
						{
							case 1:
							{
								if(s_Tenform=="CTChiDuAn")
								
								{
									frmReport f=new frmReport(a,ds_Data,title_Ngaythang,title_Taikhoan,chuky1,chuky2,chuky3,chuky4,s_Report.ToString(),sNam,sTenDA,sChuongTrinh,sMaso,sNamKD,sNamKT,title_Loai,title_Khoan,sMuc,sTenTKC2,0);
									f.ShowDialog();
								}
								else
									if(s_Tenform=="TheoDoiNguonKP"||s_Tenform=="THNguonKP")
								{
									frmReport f = new frmReport(a,ds_Data,title_Ngaythang,title_Taikhoan,chuky1,chuky2,chuky3,chuky4,s_Report,sNam,sNguonKP,"",sLoaiKP,title_Loai,title_Khoan);
									f.ShowDialog();
								}						
								else
								{
									frmReport f=new frmReport(a,ds_Data,title_Ngaythang,title_Taikhoan,title_Sotk,title_Doituong,title_Loai,title_Khoan,s_Report.ToString());
									f.ShowDialog();
								}
								break;
							
							}
							case 2:
								string s_ExcelError=exportExcel.expExcel(a,ds_Data,"",s_Thangnam,"","","","","","","","","","","",s_Report.ToString());
								if (s_ExcelError!="")
									MessageBox.Show(s_ExcelError,"Thông báo!");
								break;
							case 3:
								Print.Printer(a,ds_Data,title_Ngaythang,title_Taikhoan,title_Sotk,title_Doituong,title_Loai,title_Khoan,s_Report.ToString(),1,1);
								break;
							default:
								break;
							
						}
					}
				}
				catch
				{
					MessageBox.Show("Không có số liệu !","Thông báo !");
				}				

			}
		}

		private void butXem_Click(object sender, System.EventArgs e)
		{
			Display(1);
		}

		private void butIn_Click(object sender, System.EventArgs e)
		{
			Display(3);
		}

		private void rdbTheothang_CheckedChanged(object sender, System.EventArgs e)
		{
			grbThang.Enabled=rdbTheothang.Checked;
			grbNgay.Enabled=!rdbTheothang.Checked;
		}

		private void rdbTheongay_CheckedChanged(object sender, System.EventArgs e)
		{
			grbThang.Enabled=!rdbTheongay.Checked;
			grbNgay.Enabled=rdbTheongay.Checked;
		}
		
		private void frmReportNguon_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			try
			{
				if (a!=null) a.Dispose();
				ds_Data.Dispose();
			}
			catch{}	;
			this.Dispose();
		}
		private void txtnhombc_DoubleClick(object sender, System.EventArgs e)
		{
			if (dt_Dmnhombc!=null)
			{
				listnhombc.Focus();
				Filter_List(listnhombc,txtnhombc.Text.Trim(),"ma","TEN");
				listnhombc.BrowseToDmtk(txtnhombc,txttennhombc,txtchuong,txtnhombc.Location.X+8,128,txtnhombc.Width+txttennhombc.Width+2,txtnhombc.Height,100);				
			}
		}

		private void txtnhombc_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (dt_Dmnhombc!=null)
			{
				if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listnhombc.Focus();
				else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
				{
					if (listnhombc.Visible) 
					{
						listnhombc.Focus();
						SendKeys.Send("{Down}");
					}
					else SendKeys.Send("{Tab}");
				}
			}
			else SendKeys.Send("{Tab}");
		}

		private void txtnhombc_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtnhombc && dt_Dmnhombc!=null)
			{
				Filter_List(listnhombc,txtnhombc.Text.Trim(),"ma","TEN");
				listnhombc.BrowseToDmtk(txtnhombc,txttennhombc,txtchuong,txtnhombc.Location.X+8,128,txtnhombc.Width+txttennhombc.Width+2,txtnhombc.Height,100);				
			}	
		}

		private void txtnhombc_Validated(object sender, System.EventArgs e)
		{
			if (txtnhombc.Text!="")
			{
				r=a.getrowbyid(dt_Dmnhombc,"ma='"+txtnhombc.Text.Trim()+"'");
				if (r!=null) 
				{
					txttennhombc.Text=r["TEN"].ToString();
				}
			}
			hide_List();
		}

		private void txtchuong_DoubleClick(object sender, System.EventArgs e)
		{
			if (dt_Dmchuong!=null)
			{
				listchuong.Focus();
				Filter_List(listchuong,txtchuong.Text.Trim(),"ma","ten");
				listchuong.BrowseToDmtk(txtchuong,txttenchuong,txthoatdong,txtchuong.Location.X+8,150,txtchuong.Width+0+txttenchuong.Width,txtchuong.Height,100);
			}
		}

		private void txtchuong_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (dt_Dmchuong!=null)
			{
				if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listchuong.Focus();
				else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
				{
					if (listchuong.Visible) 
					{
						listchuong.Focus();
						SendKeys.Send("{Down}");
					}
					else SendKeys.Send("{Tab}");
				}
			}
			else SendKeys.Send("{Tab}");
		}

		private void txtchuong_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtchuong && dt_Dmchuong!=null)
			{
				Filter_List(listchuong,txtchuong.Text.Trim(),"ma","ten");
				listchuong.BrowseToDmtk(txtchuong,txttenchuong,txthoatdong,txtchuong.Location.X+8,150,txtchuong.Width+0+txttenchuong.Width,txtchuong.Height,100);
			}	
		}

		private void txtchuong_Validated(object sender, System.EventArgs e)
		{
			txttenchuong.Text="";
			if (txtchuong.Text!="")
			{
				r=a.getrowbyid(dt_Dmchuong,"ma='"+txtchuong.Text.Trim()+"'");
				if (r!=null) 
				{
					txttenchuong.Text=r["ten"].ToString();
				}
			}
			hide_List();
		}

		private void txthoatdong_DoubleClick(object sender, System.EventArgs e)
		{
			if (dt_Dmhoatdong!=null)
			{
				listhoatdong.Focus();
				Filter_List(listhoatdong,txthoatdong.Text.Trim(),"ma","ten");
				listhoatdong.BrowseToDmtk(txthoatdong,txttenhoatdong,txtLoaikhoan,txthoatdong.Location.X+8,(txthoatdong.Location.X+txthoatdong.Location.Y)-8,txthoatdong.Width+0+txttenhoatdong.Width,txthoatdong.Height,100);								
			}			
		}

		private void txthoatdong_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (dt_Dmhoatdong!=null)
			{
				if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listhoatdong.Focus();
				else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
				{
					if (listhoatdong.Visible) 
					{
						listhoatdong.Focus();
						SendKeys.Send("{Down}");
					}
					else SendKeys.Send("{Tab}");
				}
			}
		}

		private void txthoatdong_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txthoatdong && dt_Dmhoatdong!=null)
			{			
				Filter_List(listhoatdong,txthoatdong.Text.Trim(),"ma","ten");				
				listhoatdong.BrowseToDmtk(txthoatdong,txttenhoatdong,txtLoaikhoan,txthoatdong.Location.X+8,(txthoatdong.Location.X+txthoatdong.Location.Y)-8,txthoatdong.Width+0+txttenhoatdong.Width,txthoatdong.Height,100);								
			}	
		}

		private void txthoatdong_Validated(object sender, System.EventArgs e)
		{
			txttenhoatdong.Text="";
			if (txthoatdong.Text!="")
			{
				r=a.getrowbyid(dt_Dmhoatdong,"ma='"+txthoatdong.Text.Trim()+"'");
				if (r!=null) 
				{
					txttenhoatdong.Text=r["ten"].ToString();
				}
			}
			hide_List();
		}

		private void frmReportNguon_Click(object sender, System.EventArgs e)
		{
			hide_List();
		}

		private void butExcel_Click(object sender, System.EventArgs e)
		{
			Display(2);
		}		
	}
}
